package com.sgb.trip.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.trip.api.TripNet;
import com.sgb.trip.entity.InsureServiceEntity;
import com.sgb.trip.entity.PassengerInfoEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;
import java.util.Map;

/**
 * Time:2021/9/13
 * Author:黄淋
 * Description:
 */
public class FlightCheckOrderModel extends BaseViewModel {
    public MutableLiveData<List<PassengerInfoEntity>> ldPassengerData = new MutableLiveData<>();
    public MutableLiveData<List<InsureServiceEntity>> ldInsureData = new MutableLiveData<>();
    public MutableLiveData<String> ldPostData = new MutableLiveData<>();

    public FlightCheckOrderModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 加载乘机人数据
     */
    public void getPassengersList(String name) {
        TripNet.getInstance().getService().queryPassenger(name).enqueue(new ICallBack<BaseEntity<List<PassengerInfoEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PassengerInfoEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null || data.getData() == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldPassengerData.postValue(data.getData());
                }
            }

            @Override
            public void onFailureWithEntity(BaseEntity entity) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    /**
     * 加载保险数据
     */
    public void getInsureData(Map<String, Object> map) {
        TripNet.getInstance().getService().getInsureList(map).enqueue(new ICallBack<BaseEntity<List<InsureServiceEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<InsureServiceEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null || data.getData() == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldInsureData.postValue(data.getData());
                }
            }

            @Override
            public void onFailureWithEntity(BaseEntity entity) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    /**
     * 提交订单
     */
    public void postOrder(Map<String, Object> map) {
        TripNet.getInstance().getService().postFlightOrder(map).enqueue(new ICallBack<BaseEntity<String>>() {
            @Override
            public void onSuccess(BaseEntity<String> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null || data.getData() == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldPostData.postValue(data.getData());
                }
            }

            @Override
            public void onFailureWithEntity(BaseEntity entity) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

}
